<template>
<div class="container" style="text-align: left;">
  <h4>请添加患者信息</h4>
  <h5><small>以便医生给出更准确的治疗，信息仅医生可见</small></h5>
  <h6>&nbsp;</h6>
    <div class="form-group">
      <label for="name" class="col-sm-2 control-label text-left">姓名</label>
      <div class="col-sm-4">
        <el-input v-model="name" placeholder="请输入姓名" required
                  onkeyup="value=value.replace(/[\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))"></el-input>
      </div>
    </div>
    <div class="form-group">
      <label for="xb" class="col-sm-2 control-label text-left">性别</label>
      <div class="col-sm-4">
        <div class="radio-inline">
          <el-radio v-model="radio" label="1">男</el-radio>
          <el-radio v-model="radio" label="0">女</el-radio>
        </div>
      </div>
    </div>
    <div class="form-group">
    <label for="age" class="col-sm-2 control-label text-left" maxlength="3">年龄</label>
    <div class="col-sm-4">
      <el-input v-model="birthday" placeholder="请输入年龄" required maxlength="3"
      ></el-input>
    </div>
  </div>
    <div class="form-group">
      <label for="wei" class="col-sm-2 control-label text-left" >体重(公斤)</label>
      <div class="col-sm-4">
        <el-input v-model="wei" placeholder="0" required maxlength="3"></el-input>
      </div>
    </div>
    <div class="form-group">
      <label for="gms" class="col-sm-2 control-label text-left">过敏史</label>
      <div class="col-sm-4">
        <el-input
          type="textarea"
          :rows="4"
          placeholder="请填写过敏药物（非常重要）"
          v-model="textarea1">
        </el-input>
      </div>
    </div>
    <div class="form-group">
      <label for="gwbs" class="col-sm-2 control-label text-left">过往病史</label>
      <div class="col-sm-4">
        <el-input
          type="textarea"
          :rows="4"
          placeholder="请填写肝肾功能状况及过往病史（选填）"
          v-model="textarea2">
        </el-input>
      </div>
    </div>
    <button class="btn btn-success btn-lg btn-block btn-check" @click="onSubmit">提交</button>
</div>
</template>

<script>
export default {
  name: 'Third',
  data () {
    return {
      name: '',
      birthday: '',
      wei: '',
      radio: '',
      textarea1: '',
      textarea2: '',
      isV: false,
    }
  },
  methods: {
    onSubmit () {
      var symptom = localStorage.getItem('symptom')
      var time = Date()
      var now = time.split('G')
      var opid = localStorage.getItem('Opid')
      var pic = localStorage.getItem('pic')
      localStorage.setItem('oName',this.name)
      localStorage.setItem('oNow',now[0])
      localStorage.setItem('oBirthday',this.birthday)
      localStorage.setItem('oWei',this.wei)
      localStorage.setItem('oRadio',this.radio)
      localStorage.setItem('oTextarea1',this.textarea1)
      localStorage.setItem('oTextarea2',this.textarea2)
      if (this.name === '' || this.radio === '' || this.birthday === '' || this.wei === '' || symptom === '' || this.wei < 0 || this.wei > 600 || this.birthday < 0 || this.birthday > 150) {
        alert('您输入的信息不完整或者不准确')
      } else {
        if(this.isV === true){
          this.$ajax.post('http://47.75.110.31:8080/orinfo/addOne?opid=' + opid + '&patientname=' + this.name + '&sex=' + this.radio + '&birthday=' + this.birthday + '&weight=' + this.wei + '&history=' + this.textarea1 + '&symptom=' + symptom + '&past=' + this.textarea2 + '&picture=' + pic + '&times=' + now[0] + '&status=0&doctor=1',
            {
              headers: {
                'Content-Type': 'application/json;charset=UTF-8'
              }
            }
          ).then(response => {
            console.log(response.data)
            alert('恭喜您提交成功')
            localStorage.clear();
            window.close();
          })
        }else{
          this.$router.push('/isNotVip');
        }
      }
    },
    isVip() {
      var opid = localStorage.getItem('Opid')
      this.$ajax.get('http://47.75.110.31:8080/userinfo/findByOpid?opid=' + opid)
        .then(response => {
          this.order = response.data
          this.isvip = this.order[0].isvip
          if (this.isvip !== null) {
            this.isV = true;
          }
        })
    }
  },
  created() {
    this.isVip();
  },
}
</script>

<style scoped>
</style>
